# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lame
pkgver=3.100
pkgrel=5
pkgdesc="An MP3 encoder and graphical frame analyzer"
url="https://lame.sourceforge.net/"
arch="all"
license="LGPL-2.0-or-later"
subpackages="$pkgname-dev $pkgname-libs $pkgname-doc"
makedepends="nasm ncurses-dev autoconf automake libtool"
source="https://downloads.sourceforge.net/project/lame/lame/$pkgver/lame-$pkgver.tar.gz
	id3tagfix.patch
	lame.pc.in
	"

# secfixes:
#   3.99.5-r6:
#     - CVE-2015-9099
#     - CVE-2015-9100
#     - CVE-2017-9410
#     - CVE-2017-9411
#     - CVE-2017-9412
#     - CVE-2017-11720

prepare() {
	default_prepare

	# fix for parallel builds
	mkdir -p libmp3lame/i386/.libs

	# fix for pic build with new nasm
	sed -i -e '/define sp/s/+/ + /g' libmp3lame/i386/nasm.h

	aclocal && automake --force --add-missing
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-nasm \
		--disable-mp3x \
		--enable-shared \
		--with-pic
	make
}

check() {
	make test
}

package() {
	make DESTDIR="$pkgdir" install

	mkdir -p "$pkgdir"/usr/lib/pkgconfig/
	sed "s|@PKGVER@|$pkgver|" "$srcdir"/lame.pc.in \
		> "$pkgdir"/usr/lib/pkgconfig/lame.pc
}

sha512sums="
0844b9eadb4aacf8000444621451277de365041cc1d97b7f7a589da0b7a23899310afd4e4d81114b9912aa97832621d20588034715573d417b2923948c08634b  lame-3.100.tar.gz
2b47995715c526c74e782ac34778b7075fad1fa16b5299e73b2c62cdf6bfa64ba0862d18e949565aff49c613d2468794dc6e336836ed4ebdb2e6ef67be8af5b0  id3tagfix.patch
ace7813debdb2cd8b08c26e99db50776180b05105832db96ad0bb314dc3e1eadccfd14de3adab7b1a37b6df7d521b5216ed7d9c3c11d5bae388197debca58f0f  lame.pc.in
"
